//
//  ZHSearchNavView.m
//  sc-cyan-ios
//
//  Created by lj on 2018/1/4.
//  Copyright © 2018年 greenbuilding. All rights reserved.
//

#import "ZHSearchNavView.h"

@interface ZHSearchNavView()<UITextFieldDelegate>

@property (weak, nonatomic) IBOutlet UITextField *searchF;
@property (weak, nonatomic) IBOutlet UIButton *loctionBtn;

@end

@implementation ZHSearchNavView

- (void)awakeFromNib{
    [super awakeFromNib];
    
    self.autoresizingMask = UIViewAutoresizingNone;
    
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sy_sousuo01"]];
    imageView.x = 10;
    UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, self.searchF.height)];
    
    imageView.centerY = leftView.centerY;
    leftView.width = imageView.x + imageView.width + 5;
    
    [leftView addSubview:imageView];
    self.searchF.leftView = leftView;
    self.searchF.leftViewMode = UITextFieldViewModeAlways;
    self.searchF.layer.cornerRadius = 2;
    self.searchF.layer.borderColor = [UIColor gb_line_d4d4d4].CGColor;
    self.searchF.layer.borderWidth = 1;
    self.searchF.layer.masksToBounds = YES;
    self.searchF.backgroundColor = UIColorFromRGB(0xf7f7f7);
    self.searchF.delegate = self;
    
}

- (void)setLoction:(NSString *)loction{
    _loction = loction;
    
    [_loctionBtn setTitle:loction forState:UIControlStateNormal];
}

- (IBAction)backAction:(id)sender {
    if (self.popAction) {
        self.popAction();
    }
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    if (self.searchAction) {
        self.searchAction(textField.text);
    }
    
    return YES;
}

@end
